home *** CD-ROM | disk | FTP | other *** search
- /*
- * File Name: Utilities.c
- *
- * Description: Miscellaneous utilities for use with the sample JPEG converter.
- *
- * Written by: David Gelphman 04/03/98
- *
- * Copyright: © 1998 by Apple Computer Inc., All Rights Reserved.
- *
- * Change History (most recent first):
- *
- * 04/03/98 DMG457 First version of this file.
- *
- */
-
- #include "Utilities.h"
- #include "PSWriterErr.h"
-
- OSStatus getHint(Collection hints, CollectionTag tag, long id, long hintSize, void *data)
- {
- long itemSize;
- OSStatus err;
-
- itemSize = hintSize;
- err = GetCollectionItem(hints, tag, id, &itemSize, data);
- if(!err && itemSize != hintSize) err = errHintWrongSize;
-
- return err;
- }
-
- void *copyPStr(StringPtr dest, ConstStringPtr src, Size bufSize)
- /* Copy the pascal String 'src' to 'dest' max size bufSize. Returning pointer after dest string.
- If the Destination string is shorter than the source string, the string size is reduced appropriately.
- Moved from a macro to a routine as we weren't updating the dest length byte
- correctly:.
- */
- {
- int len;
-
- /* Figure out how many bytes to copy. If the buffer is
- bigger than the Pascal String (minus the length byte)
- then copy the whole string plus the length byte. Otherwise
- just fill the buffer.
- */
- len = bufSize > *src ? *src + 1: bufSize;
- (void) memcpy(dest, src, len);
- *dest = len - 1; // Update the length byte.
-
- return dest + len;
- }
-
- void pNStrCat(StringPtr base, const Byte *more, Size baseSize)
- /* Concatenate the pascal String 'more' to the back of
- the pascal String 'base'. This function will make sure
- that the resulting Pascal string fits in a buffer with
- 'baseSize' bytes.
- */
- {
- Size bytesToCopy = baseSize - *base - 1;
-
- if(*more < bytesToCopy) bytesToCopy = *more;
-
- if(bytesToCopy > 0){
- bcopy(more + 1, afterPSTR(base), bytesToCopy);
- *base += bytesToCopy;
- }
- }
-
- void CopyCtoPstr(StringPtr dst, char* src)
- {
- unsigned char *firstP = dst++;
- unsigned char count = 0;
-
- while((count < 255) && (*dst++ = *src++) != 0)
- count++;
- *firstP = count;
- }
-
- void psDisposePtr(Ptr ptr){
- if(ptr)
- DisposePtr(ptr);
- }